import env
import mcrud
import ampractice
import amauth
import mauth
import snowflake
import amuserdetail
import amstudent
import amcountdown

env.load("../product.env")
# env.load(".env")
db = mcrud.new_env()

ampractice.init_table_problem(db)
ampractice.init_table_practice(db)
amuserdetail.init_table(db)
amstudent.init_table_student(db)
amstudent.init_table_record(db)
amcountdown.init_table_num(db)

username = "zhangdapeng"
password = "zhangdapeng520"
amauth.data.init(db, username, password)

user = mauth.user.get(db, username, password)
admin_role_id = snowflake.idstr()
common_role_id = snowflake.idstr()
mauth.role.add(db, admin_role_id, "admin", "超级管理员")
mauth.role.add(db, common_role_id, "common", "普通用户")

problem_add_id = snowflake.idstr()
mauth.auth.add(db, problem_add_id, "/problem/add", "前端添加习题")
practice_redo_id = snowflake.idstr()
mauth.auth.add(db, practice_redo_id, "/practice/redo", "重做")
course_list_id = snowflake.idstr()
mauth.auth.add(db, course_list_id, "/student/course_list", "课程列表")
record_add_id = snowflake.idstr()
mauth.auth.add(db, record_add_id, "/student/record_add", "添加上课记录")
student_add_id = snowflake.idstr()
mauth.auth.add(db, student_add_id, "/student/add", "添加学生")
student_list_id = snowflake.idstr()
mauth.auth.add(db, student_list_id, "/student/list", "学生列表")
record_list_id = snowflake.idstr()
mauth.auth.add(db, record_list_id, "/student/record_list", "上课记录列表")

mauth.userrole.add(db, snowflake.idstr(), user.get("id"), admin_role_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, problem_add_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, practice_redo_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, course_list_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, record_add_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, student_add_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, student_list_id)
mauth.roleauth.add(db, snowflake.idstr(), admin_role_id, record_list_id)

print(mauth.user.get_auths_by_id(db, user.get("id")))
